﻿
using MMPS.Common;
using MMPS.Entity.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MemberPoint.Business;
using MMPS.Business;
using MMPS.Entity.POCOMdel;

namespace MemberPoint.Business
{
    public class ShopsAddService:BaseService<Shops>
    {
        #region 添加
        public OperateResult GetAddShops(GetPageShopsView ShopsAdd)
        {
            
            Shops shops = new Shops();
            shops.S_Name = ShopsAdd.S_Name;
            shops.S_Remark = ShopsAdd.S_Remark;
            shops.S_IsHasSetAdmin = ShopsAdd.S_IsHasSetAdmin;
            shops.S_CreateTime = ShopsAdd.S_CreateTime;
            shops.S_ContactTel = ShopsAdd.S_ContactTel;
            shops.S_ContactName = ShopsAdd.S_ContactName;
            shops.S_Category = ShopsAdd.S_Category;
            shops.S_Address = ShopsAdd.S_Address;
            var result=Add(shops);
            if (result)
            {
                return new OperateResult(ResultStatus.Success, "添加成功");
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "添加失败");
            }

        }
        #endregion
        #region 修改
        public OperateResult Edit(int id)
        {
            Shops list = Find(e => e.S_ID == id);
            if (list!=null)
            {
                GetPageShopsView getPageShopsView = new GetPageShopsView();
                getPageShopsView.S_ID = list.S_ID;
                getPageShopsView.S_Name = list.S_Name;
                getPageShopsView.S_Remark = list.S_Remark;
                getPageShopsView.S_IsHasSetAdmin = list.S_IsHasSetAdmin;
                getPageShopsView.S_CreateTime = list.S_CreateTime;
                getPageShopsView.S_ContactTel = list.S_ContactTel;
                getPageShopsView.S_ContactName = list.S_ContactName;
                getPageShopsView.S_Category = list.S_Category;
                getPageShopsView.S_Address = list.S_Address;
                return new OperateResult(ResultStatus.Success, "修改加载成功", getPageShopsView);
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "修改加载失败");
            }
        }
        public OperateResult Edit(GetPageShopsView ShopsAdd)
        {
            var list = Find(s => s.S_ID == ShopsAdd.S_ID);
            if (list != null)
            {
                list.S_Name = ShopsAdd.S_Name;
                list.S_Remark = ShopsAdd.S_Remark;
                list.S_IsHasSetAdmin = ShopsAdd.S_IsHasSetAdmin;
                list.S_CreateTime = ShopsAdd.S_CreateTime;
                list.S_ContactTel = ShopsAdd.S_ContactTel;
                list.S_ContactName = ShopsAdd.S_ContactName;
                list.S_Category = ShopsAdd.S_Category;
                list.S_Address = ShopsAdd.S_Address;
                var result = Update(list);
                if (result)
                {
                    return new OperateResult(ResultStatus.Success, "修改成功");
                }
                else
                {
                    return new OperateResult(ResultStatus.Error, "修改失败");
                }
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "该用户不存在");
            }
            

        }
        #endregion
        #region 删除
        public OperateResult Delete(int id)
        {
            Shops list = Find(e => e.S_ID == id);
            if (list != null)
            {
               var result= Delete(list);
                if (result)
                {
                    return new OperateResult(ResultStatus.Success, "删除成功");
                }
                else
                {
                    return new OperateResult(ResultStatus.Error, "删除失败");
                }
                
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "该用户异常");
            }
        }
        #endregion

    }
}
